local skel = fk.CreateSkill {
  name = "lb_zero__liebu",
}

Fk:loadTranslationTable {
  ["lb_zero__liebu"] = "猎步",
  [":lb_zero__liebu"] = "每回合限一次，你距离1以内的角色使用基本牌或普通锦囊牌指定唯一目标后，若目标角色为你上张伤害牌的目标，你可以将一张牌当【过河拆桥】对目标角色使用。" ..
      "<a href='os__guerrilla'>游击</a>：此牌视为由你使用并额外结算一次。",

  ["#lb_zero__liebu"] = "猎步：你可以将一张牌当【过河拆桥】对 %src 使用",
  ["@[player_chara]lb_zero__liebu"] = "猎步",

  ["$lb_zero__liebu1"] = "机会难得，可要让我尽兴哦~",
  ["$lb_zero__liebu2"] = "求饶还来得及哦~骗你的。",
}

skel:addEffect(fk.TargetSpecified, {
  can_trigger = function(self, event, target, player, data)
    if data:isOnlyTarget(data.to) and player:hasSkill(skel.name)
        and not data.to.dead and player:distanceTo(target) <= 1
        and player:usedSkillTimes(skel.name) == 0
        and (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) then
      local useParent = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
      if useParent == nil then return false end
      local lastUseEvent = player.room.logic:getEventsByRule(GameEvent.UseCard, 1, function(e)
        local use = e.data
        return e.id < useParent.id and use.from == player and use.card.is_damage_card
      end, 0)[1]
      if lastUseEvent == nil then return false end
      local last_use = lastUseEvent.data
      return table.contains(last_use.tos, data.to)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askToUseVirtualCard(player, {
      name = "dismantlement",
      skill_name = skel.name,
      cancelable = true,
      card_filter = {
        n = 1
      },
      extra_data = { must_targets = { data.to.id } },
      prompt = "#lb_zero__liebu:" .. data.to.id,
      skip = true,
    })
    if use then
      event:setCostData(self, { use = use })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:useCard(event:getCostData(self).use)
    if player:inMyAttackRange(data.to) and not data.to:inMyAttackRange(player) then
      data.from = player
      data.use.additionalEffect = (data.use.additionalEffect or 0) + 1
    end
  end,
})

skel:addEffect(fk.CardUseFinished, {
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(skel.name, true) and target == player and data.card.is_damage_card
  end,
  on_refresh = function (self, event, target, player, data)
    skel:onAcquire(player, false)
  end,
})

skel:addAcquireEffect(function(self, player, is_start)
  local room = player.room
  local lastUseEvent = player.room.logic:getEventsByRule(GameEvent.UseCard, 1, function(e)
    local use = e.data
    return use.from == player and use.card.is_damage_card
  end, 0)[1]
  if lastUseEvent == nil then return end
  local last_use = lastUseEvent.data
  room:setPlayerMark(player, "@[player_chara]lb_zero__liebu", #last_use.tos == 0 and 0 or table.map(last_use.tos, Util.IdMapper))
end)

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@[player_chara]lb_zero__liebu", 0)
end)

return skel
